using Caliburn.Core.Metadata;
using Caliburn.PresentationFramework;
using Caliburn.PresentationFramework.ApplicationModel;
using Common.Dao;
using Common.Dao.Impl;
using Common.Model;

namespace HRManager.ViewModels
{
    [PerRequest(typeof(TrainingCourseDetailViewModel))]
    public class TrainingCourseDetailViewModel:Presenter
    {
        private TrainingCourse _trainingCourse;

        public TrainingCourseDetailViewModel(IRepository repository)
        {
            this._repository = repository;
        }

        public TrainingCourse TrainingCourse
        {
            get { return _trainingCourse; }
            set
            {
                _trainingCourse = value;
                NotifyOfPropertyChange(()=>this.TrainingCourse);
            }
        }

        private BindableCollection<Employee> _employees;

        public BindableCollection<Employee> Employees
        {
            get { return _employees; }
            set
            {
                _employees = value;
                NotifyOfPropertyChange(() => this.Employees);
            }
        }

        public BindableCollection<TrainingClass> TrainingClasses
        {
            get; set;
        }

        public override void Activate()
        {
            if (this.TrainingCourse == null)
            {
                var newTrainingCourse = new TrainingCourse
                                            {
                                                TrainingClass = new TrainingClass(),
                                                Observation = new Employee(),
                                                Trainer = new Employee()
                                            };
                this.TrainingCourse = newTrainingCourse;
            }

            this.TrainingClasses = new BindableCollection<TrainingClass>(this._repository.LoadAll<TrainingClass, int>());
        }

        public IResult SubmitTrainingCourse()
        {
            var trainingCourse = this.TrainingCourse;
            return null;
        }

        public IRepository _repository { get; set; }
    }
}